#include <iostream>
#include <vector>
using namespace std;

void eat_amount(int n,vector<char*>& list,int current, int size){
    if(size==0)
		return;
	while(1){
		if(current+size>n)
			break;
		try{
		list.push_back(new char[size]);
		}
		catch(std::bad_alloc){
			break;
		}
	 	current+=size;
	    cout<<size<<endl;
	}
	eat_amount(n,list,current,size/2);
}

int main(void){
	vector<char*> list;
    eat_amount(123456,list,0,200000); 	
    for(int i=0; i<list.size(); i++)
		delete [] list[i];
	system("pause");
	return 0;
}

